let list = [
    {"name": "John","Average":15,"High":10,"DtmStamp":1358226000000},
    {"name": "Jane","Average":16,"High":92,"DtmStamp":1358226000000},
    {"name": "Jane","Average":17,"High":45,"DtmStamp":1358226000000},
    {"name": "John","Average":18,"High":87,"DtmStamp":1358226000000},
    {"name": "Jane","Average":15,"High":10,"DtmStamp":1358226060000},
    {"name": "John","Average":16,"High":87,"DtmStamp":1358226060000},
    {"name": "John","Average":17,"High":45,"DtmStamp":1358226060000},
    {"name": "Jane","Average":18,"High":92,"DtmStamp":1358226060000}
];
let listA = [
    {"id":"1","title": "威海2018年体育中考内容出炉炉","date":"20180212"},
    {"id":"2","title": "小年开始威海市区将进入亮灯模","date":"20180211"},
    {"id":"3","title": "威海市图书馆2月8日免费送春","date":"20180208"},
    {"id":"4","title": "92号汽油每升上涨5分钱分钱分","date":"20180208"},
    {"id":"5","title": "市民可免费领手绘版“威海文化","date":"20180208"},
    {"id":"6","title": "首批52辆新能源车23日上牌分","date":"20180208"},
    {"id":"7","title": "高区幼儿园招聘24名幼儿教师","date":"20180207"},
    {"id":"8","title": "威海-北京新增春节加班航班炉","date":"20180207"}
];
function changeDate(arr) {
    const a = {};
    const d = new Date();
    const today = `${d.getFullYear()}${d.getDate()}${d.getDay()}`;
    arr.forEach((v,index)=>{
        console.log(today)
        console.log(v.date)
        const c = today - v.date;
        console.log(
            `${c}
`);

        if(v.date < today){
            v.date = 'yestoday'
        }

        a[index] =[]
        a[index].push(v)
    })
    return a
}

let d = changeDate(listA);
console.log(d)


function groupBy( array , f ) {
    let groups = {};
    array.forEach( function( o ) {
        let group = JSON.stringify( f(o) );
        // console.log(group) John
        // Jane
        groups[group] = groups[group] || [];
        groups[group].push( o );
    });
    console.log(groups)
    // let b = Object.keys(groups);
    // console.log(b)
    return Object.keys(groups).map( function( g ) {
        return groups[g];
    });
}
// let sorted = groupBy(list, function(item){
//     return [item.name];
// });
let a = groupBy(list, item => item.name);
console.log(a);

var arr = [
    {time:'2017-12-07',title:'现在天气冷了'},
    {time:'2017-12-07',title:'什么时候变热'},
    {time:'2017-12-08',title:'什么时候过年'},
    {time:'2017-12-08',title:'春节放假怎么安排'},
    {time:'2017-12-09',title:'春节放假怎么安排'},
    {time:'2017-12-09',title:'春节放假怎么安排'},
]
var json = {}
// arr.forEach(function(v){
//     if(json[v.time]){
//         json[v.time].push(v);
//     }else{
//         json[v.time] = [v];
//     }
// })
// arr.forEach(function(v,index){
//     console.log(v)
//     if(json[v.time]){
//         json[v.time].push(v.title);
//     }
// })

// console.log(json)

var arr = [ 'Car', 'Car', 'Truck', 'Boat', 'Truck' ];
var hist = {};
arr.map( function (a) { if (a in hist) hist[a] ++; else hist[a] = 1; } );
console.log(hist);

//
function xGroup(array,key) {
    let arr = {}
    array.forEach(function(v){
        if(arr[v.key]){
            arr[v.key].push(v);
        }
        else{
            arr[v.key] = [v];
        }
    })
    return arr;
}
// console.log(xGroup(arr,))
